﻿package frEngine.shader.filters.fragmentFilters
{
    import __AS3__.vec.*;
    import frEngine.shader.*;
    import frEngine.shader.filters.*;

    public class TangentNormalMapFilter extends FilterBase
    {
        private var defautltTangent:Vector.<Number>;
        public var UseDefaultTangent:Boolean = true;

        public function TangentNormalMapFilter()
        {
            this.defautltTangent = this.Vector.<Number>([1, 0, 0, 0]);
            super(FilterType.TangentNormalMapFilter, FilterPriority.TangentNormalMapFilter);
            return;
        }// end function

        override public function setRegisterParams(param1:Program3dRegisterInstance) : void
        {
            return;
        }// end function

        override public function get programeId() : String
        {
            return "TangentNormalMap0";
        }// end function

        override public function clone() : FilterBase
        {
            return this;
        }// end function

        override public function createVertexCode(param1:Program3dRegisterInstance, param2:int) : String
        {
            var _loc_3:* = new Array();
            if (!this.UseDefaultTangent)
            {
                _loc_3.push(new ToBuilderInfo("vf2", "{TANGENT}", false, 1));
            }
            param1.toBuild("", _loc_3);
            return "";
        }// end function

        override public function createFragmentColor(param1:Program3dRegisterInstance, param2:Boolean) : String
        {
            var _loc_3:* = new Array();
            var _loc_4:String = "{TANGENT}";
            if (this.UseDefaultTangent)
            {
                _loc_3.push(new ToBuilderInfo("fc1", "{MyTangent}", false, 1, this.defautltTangent));
                _loc_4 = "{MyTangent}";
            }
            _loc_3.push(new ToBuilderInfo("ft1", "{TgLine1}", false, 1));
            _loc_3.push(new ToBuilderInfo("ft2", "{TgLine2}", false, 1));
            _loc_3.push(new ToBuilderInfo("ft3", "{TgLine3}", false, 1));
            var _loc_5:* = compileTangentNormalMapFragmentCode("{vnormal}", _loc_4, "ft1", "ft2", "ft3", "ft4");
            _loc_5 = param1.toBuild(_loc_5, _loc_3);
            return _loc_5;
        }// end function

        public static function compileTangentNormalMapFragmentCode(param1:String, param2:String, param3:String, param4:String, param5:String, param6:String) : String
        {
            var _loc_7:* = "mov " + param3 + ".x, " + param2 + ".x \n" + "mov " + param3 + ".z, " + param1 + ".x \n" + "mov " + param3 + ".w, " + param1 + ".w \n" + "mov " + param4 + ".x, " + param2 + ".y \n" + "mov " + param4 + ".z, " + param1 + ".y \n" + "mov " + param4 + ".w, " + param1 + ".w \n" + "mov " + param5 + ".x, " + param2 + ".z \n" + "mov " + param5 + ".z, " + param1 + ".z  \n" + "mov " + param5 + ".w, " + param1 + ".w \n" + "crs " + param6 + ".xyz, " + param1 + ", " + param2 + " \n" + "mov " + param3 + ".y, " + param6 + ".x \n" + "mov " + param4 + ".y, " + param6 + ".y \n" + "mov " + param5 + ".y, " + param6 + ".z \n" + "nrm " + param3 + ".xyz, " + param3 + " \n" + "mov " + param3 + ".w, " + param3 + ".w \n" + "nrm " + param4 + ".xyz, " + param4 + " \n" + "nrm " + param5 + ".xyz, " + param5 + " \n" + "\n";
            return _loc_7;
        }// end function

        public static function compileNormalMapMulMatrixFragmentCode(param1:String, param2:String) : String
        {
            var _loc_3:* = "m33 " + param1 + ".xyz, " + param1 + ", " + param2 + "\t \n" + "mov " + param1 + ".w,   " + param2 + ".w \n" + "\n";
            return _loc_3;
        }// end function

    }
}
